<?php
/**
 * Created by PhpStorm.
 * User: mr.houhai
 * Date: 2018/2/26
 * Time: 0:35
 */

namespace Xcx\Model;

class GoodsOrderAddressModel extends BaseModel
{

    /**
     * 添加地址信息
     * @param $orderNo
     * @param $id
     * @return mixed
     */
    public function addOrderAddress($orderNo, $id)
    {
        $address = $this->getAddressInfo($id);

        $data['order_no'] = $orderNo;
        $data['name'] = $address['name'];
        $data['phone'] = $address['phone'];
        $data['province'] = $address['province'];
        $data['city'] = $address['city'];
        $data['area'] = $address['area'];
        $data['address'] = $address['address'];
        $data['add_time'] = time();

        //先删除该订单历史地址信息，再添加新的地址信息
        $this->where(array('order_no'=>$orderNo))->delete();
        return $this->data($data)->add();
    }

    /**
     * 获取地址信息
     * @param $id
     * @return array|false|mixed|\PDOStatement|string|\think\Model
     */
    private function getAddressInfo($id)
    {
        $Address = new AddressModel();
        return $Address->getAddressDetailsInfo($id);
    }

}